{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Histograms in Scala\n",
    "\n",
    "In a histogram, the height of each bar (bin) represents the number of data points that fall into its interval.\n",
    "They are generally used to show the distribution of a variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// Generate some random data\n",
    "\n",
    "val random = new scala.util.Random\n",
    "\n",
    "val (data1, data2) = (for {\n",
    "    _ <- 1 to 10000\n",
    "    v1 = random.nextGaussian\n",
    "    v2 = random.nextGaussian * 2 + 1\n",
    "} yield (v1, v2)).unzip\n",
    "\n",
    "println(data1(7))\n",
    "OutputCell.HIDDEN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram { data = data1; binCount = 25 }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram { initWidth = 800; initHeight = 200\n",
    "              title = \"Wide Histogram with Manual Parameters\"\n",
    "              xLabel = \"Size\"\n",
    "              yLabel = \"Count\"\n",
    "              rangeMin = -8\n",
    "              rangeMax = 8\n",
    "              data = data1 ++ Seq.fill(200)(7.0)\n",
    "              binCount = 99\n",
    "              color = new Color(0, 154, 166)}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{title = \"Default is Overlap\"\n",
    "              data = Seq(data1, data2)\n",
    "              binCount = 99\n",
    "              names = Seq(\"old and tired\", \"new and improved\")\n",
    "              color = Seq(new Color(0, 154, 166),\n",
    "                      new Color(230, 50, 50, 128) // transparent!\n",
    "                     )}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{title = \"Stack\"\n",
    "              showLegend = false\n",
    "              displayMode = Histogram.DisplayMode.STACK\n",
    "              data = Seq(data1, data2)\n",
    "              binCount = 99}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{title =\"Side by Side\"\n",
    "              displayMode = Histogram.DisplayMode.SIDE_BY_SIDE\n",
    "              data = Seq(data1,data2)\n",
    "              binCount = 55}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{title = \"Cumulative\"\n",
    "              cumulative = true\n",
    "              data = data1\n",
    "              binCount = 55}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{title = \"Normed, Area = 1.0\"\n",
    "              normed = true\n",
    "              data = data1\n",
    "              binCount = 55}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new Histogram{log = true\n",
    "              data = data1\n",
    "              binCount = 99}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "",
   "name": "Scala",
   "nbconverter_exporter": "",
   "version": "2.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
